<template>
  <div class="login-container">
    <div class="login-background"></div>
    <div class="floating-leaves">
      <span class="leaf" v-for="i in 20" :key="i" :style="getLeafStyle()">🍃</span>
    </div>
    
    <div class="login-card">
      <div class="login-header">
        <div class="logo-section">
          <span class="logo-icon">
              <svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="#4CAF50" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
                <path d="M12,2 C15,4 18,7 18,12 C18,17 15,20 12,22 C9,20 6,17 6,12 C6,7 9,4 12,2 Z M12,5 C10,5 8,6 8,8 C8,10 10,11 12,13 C14,11 16,10 16,8 C16,6 14,5 12,5 Z" />
                <path d="M12,13 L12,22" />
                <path d="M7,13 L17,13" />
                <path d="M9,16 L15,16" />
              </svg>
            </span>
          <h1 class="app-title">绿碳圈</h1>
        </div>
        <p class="subtitle">与我们一起，开启绿色生活之旅</p>
      </div>

      <div class="login-tabs">
        <button 
          :class="['tab-btn', { active: isLogin }]" 
          @click="switchTab(true)"
        >
          登录
        </button>
        <button 
          :class="['tab-btn', { active: !isLogin }]" 
          @click="switchTab(false)"
        >
          注册
        </button>
      </div>

      <form @submit.prevent="handleSubmit" class="login-form">
        <div class="form-group">
          <div class="input-wrapper">
            <span class="input-icon"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg></span>
            <input
              v-model="formData.username"
              type="text"
              placeholder="请输入用户名/邮箱"
              required
              class="form-input"
              :class="{ 'error': validationErrors.username }"
              @blur="validateUsername"
              @input="validateUsername"
            />
          </div>
        </div>

        <div class="form-group">
          <div class="input-wrapper">
            <span class="input-icon"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg></span>
            <input
              v-model="formData.password"
              :type="showPassword ? 'text' : 'password'"
              placeholder="请输入密码"
              required
              class="form-input"
              :class="{ 'error': validationErrors.password }"
              @blur="validatePassword"
              @input="validatePassword"
            />
            <button 
              type="button" 
              @click="showPassword = !showPassword" 
              class="toggle-password"
            >
              <svg v-if="showPassword" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#388E3C" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                <path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path>
                <circle cx="12" cy="12" r="3"></circle>
              </svg>
              <svg v-else xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#388E3C" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                <path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path>
                <line x1="12" y1="8" x2="12" y2="16"></line>
                <line x1="8" y1="12" x2="16" y2="12"></line>
              </svg>
            </button>
          </div>
        </div>

        <div v-if="!isLogin" class="form-group">
          <div class="input-wrapper">
            <span class="input-icon"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg></span>
            <input
              v-model="formData.confirmPassword"
              :type="showPassword ? 'text' : 'password'"
              placeholder="确认密码"
              required
              class="form-input"
              :class="{ 'error': validationErrors.confirmPassword }"
              @blur="validateConfirmPassword"
              @input="validateConfirmPassword"
            />
          </div>
        </div>

        <div v-if="!isLogin" class="form-group">
          <div class="input-wrapper">
            <span class="input-icon"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"></path><polyline points="22,6 12,13 2,6"></polyline></svg></span>
            <input
              v-model="formData.email"
              type="email"
              placeholder="请输入邮箱（选填）"
              class="form-input"
              :class="{ 'error': validationErrors.email }"
              @blur="validateEmail"
              @input="validateEmail"
            />
          </div>
        </div>

        <div v-if="isLogin" class="form-options">
          <label class="remember-me">
            <input type="checkbox" v-model="formData.rememberMe" />
            <span>记住我</span>
          </label>
          <a @click.prevent="handleForgotPassword" class="forgot-password">忘记密码?</a>
        </div>

        <button type="submit" class="submit-btn" :disabled="loading || !isFormValid">
          <span v-if="!loading">{{ isLogin ? '登录' : '注册' }}</span>
          <span v-else class="loading-spinner">⏳ 处理中...</span>
        </button>

        <div class="form-group terms-checkbox">
          <label class="terms-label">
            <input type="checkbox" v-model="formData.agreeTerms" />
            <span>{{ isLogin ? '登录' : '注册' }}即表示同意 
              <router-link to="/user-agreement" class="policy-link">《用户协议》</router-link> 和 
              <router-link to="/privacy-policy" class="policy-link">《隐私政策》</router-link>
            </span>
          </label>
        </div>

        <div v-if="errorMessage" class="error-message">
          {{ errorMessage }}
        </div>
        
        <!-- 字段验证错误信息 -->
        <div v-if="validationErrors.username" class="field-error">
          {{ validationErrors.username }}
        </div>
        <div v-if="validationErrors.password" class="field-error">
          {{ validationErrors.password }}
        </div>
        <div v-if="validationErrors.confirmPassword" class="field-error">
          {{ validationErrors.confirmPassword }}
        </div>
        <div v-if="validationErrors.email" class="field-error">
          {{ validationErrors.email }}
        </div>
      </form>

      <div class="login-footer">
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, computed } from 'vue'
import { useRouter } from 'vue-router'
import { login, register } from '../api/auth'
import request from '../utls/require'

const router = useRouter()
const isLogin = ref(true)
const showPassword = ref(false)
const loading = ref(false)
const errorMessage = ref('')

// 表单验证状态
const validationErrors = reactive({
  username: '',
  password: '',
  confirmPassword: '',
  email: ''
})

const formData = reactive({
  username: '',
  password: '',
  confirmPassword: '',
  email: '',
  rememberMe: false,
  agreeTerms: false
})

const switchTab = (login: boolean) => {
  isLogin.value = login
  errorMessage.value = ''
  formData.password = ''
  formData.confirmPassword = ''
  formData.agreeTerms = false
  // 清空验证错误信息
  Object.keys(validationErrors).forEach(key => {
    validationErrors[key as keyof typeof validationErrors] = ''
  })
}

// 验证用户名
const validateUsername = () => {
  const username = formData.username.trim()
  if (!username) {
    validationErrors.username = '用户名不能为空'
    return false
  } else if (username.length < 3) {
    validationErrors.username = '用户名至少3个字符'
    return false
  } else {
    validationErrors.username = ''
    return true
  }
}

// 验证密码
const validatePassword = () => {
  const password = formData.password
  if (!password) {
    validationErrors.password = '密码不能为空'
    return false
  } else if (password.length < 6) {
    validationErrors.password = '密码至少6个字符'
    return false
  } else {
    validationErrors.password = ''
    return true
  }
}

// 验证确认密码
const validateConfirmPassword = () => {
  if (!isLogin.value) {
    if (!formData.confirmPassword) {
      validationErrors.confirmPassword = '请确认密码'
      return false
    } else if (formData.password !== formData.confirmPassword) {
      validationErrors.confirmPassword = '两次输入的密码不一致'
      return false
    } else {
      validationErrors.confirmPassword = ''
      return true
    }
  }
  return true
}

// 验证邮箱（选填）
const validateEmail = () => {
  if (!isLogin.value) {
    const email = formData.email.trim()
    // 邮箱为空时视为有效
    if (!email) {
      validationErrors.email = ''
      return true
    }
    // 邮箱不为空时验证格式
    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
    if (!emailRegex.test(email)) {
      validationErrors.email = '请输入有效的邮箱地址'
      return false
    } else {
      validationErrors.email = ''
      return true
    }
  }
  return true
}

// 检查表单是否有效
const isFormValid = computed(() => {
  const validations = [
    validateUsername(),
    validatePassword(),
    validateConfirmPassword(),
    validateEmail()
  ]
  return validations.every(v => v) && formData.agreeTerms
})

const getLeafStyle = () => {
  const randomLeft = Math.random() * 100
  const randomDuration = 10 + Math.random() * 20
  const randomDelay = Math.random() * 10
  const randomSize = 1 + Math.random() * 1.5
  
  return {
    left: `${randomLeft}%`,
    animationDuration: `${randomDuration}s`,
    animationDelay: `${randomDelay}s`,
    fontSize: `${randomSize}rem`,
    opacity: 0.3 + Math.random() * 0.4
  }
}

const handleSubmit = async () => {
  console.log('[Login] 开始处理登录/注册表单')
  errorMessage.value = ''
  
  // 执行所有验证
  validateUsername()
  validatePassword()
  validateConfirmPassword()
  validateEmail()
  
  // 验证是否同意协议
  if (!formData.agreeTerms) {
    errorMessage.value = '请阅读并同意用户协议和隐私政策'
    console.log('[Login] 用户未同意协议')
    return
  }
  
  // 如果表单无效，不提交
  if (!isFormValid.value) {
    errorMessage.value = '请检查并修正表单中的错误'
    console.log('[Login] 表单验证失败')
    return
  }
  
  // 原有验证逻辑已被表单验证替代

  loading.value = true
  console.log('[Login] 开始请求后端接口')
  
  try {
    if (isLogin.value) {
      console.log('[Login] 执行登录操作')
      // 调用登录接口
      const response: any = await login({
        username: formData.username,
        password: formData.password
      })
      
      // 200 成功
      if (response.success) {
        console.log('[Login] 登录成功', response)
        // 默认使用sessionStorage存储用户信息，如果用户选择了"记住我"，则使用localStorage
        const storage = formData.rememberMe ? localStorage : sessionStorage
        storage.setItem('userToken', response.data.token)
        storage.setItem('username', response.data.username)
        console.log('[Login] 存储用户信息到', storage === localStorage ? 'localStorage' : 'sessionStorage')
        
        // 立即获取用户详细信息（包括头像、积分等）
        try {
          console.log('[Login] 获取用户详细信息')
          const userInfoResponse: any = await request({
            url: '/xiangsu/current-user/',
            method: 'get'
          })
          console.log('[Login] 用户详细信息获取成功', userInfoResponse)
          
          if (userInfoResponse.success && userInfoResponse.data) {
            const av = userInfoResponse.data.avatar_url || userInfoResponse.data.avatar || ''
            storage.setItem('userAvatar', av)
            storage.setItem('userPoints', userInfoResponse.data.points || 0)
            console.log('[Login] 存储用户详细信息', {
              avatar: userInfoResponse.data.avatar_url,
              points: userInfoResponse.data.points
            })
            
            // 获取并存储用户统计数据
            try {
              console.log('[Login] 获取用户统计数据')
              const statisticsResponse: any = await request({
                url: '/xiangsu/user/statistics/',
                method: 'get'
              })
              console.log('[Login] 用户统计数据获取成功', statisticsResponse)
              
              if (statisticsResponse.success && statisticsResponse.data) {
                storage.setItem('userStatistics', JSON.stringify({
                  posts_count: statisticsResponse.data.posts_count || 0,
                  completed_challenges_count: statisticsResponse.data.completed_challenges_count || 0,
                  carbon_records_count: statisticsResponse.data.carbon_records_count || 0
                }))
                console.log('[Login] 存储用户统计数据', {
                  posts_count: statisticsResponse.data.posts_count,
                  completed_challenges_count: statisticsResponse.data.completed_challenges_count,
                  carbon_records_count: statisticsResponse.data.carbon_records_count
                })
              }
            } catch (statsError) {
              console.error('[Login] 获取用户统计数据失败:', statsError)
            }
          }
        } catch (error) {
          console.error('[Login] 登录后获取用户详细信息失败:', error)
          // 即使获取失败也继续登录流程
        }
        
        router.push('/')
      } else {
        // 后端返回 success: false
        errorMessage.value = response.message || '登录失败'
        console.log('[Login] 登录失败', response.message)
      }
    } else {
      console.log('[Login] 执行注册操作')
      // 调用注册接口
      const response: any = await register({
        username: formData.username,
        password: formData.password,
        email: formData.email
      })
      
      // 201 成功
      if (response.success) {
        console.log('[Login] 注册成功', response)
        showMessage('注册成功！请登录','success')
        isLogin.value = true
        formData.password = ''
        formData.confirmPassword = ''
        formData.email = ''
      } else {
        errorMessage.value = response.message || '注册失败'
        console.log('[Login] 注册失败', response.message)
      }
    }
  } catch (error: any) {
    console.error('[Login] 操作失败:', error)
    
    // 处理各种 HTTP 错误状态码
    if (error.response) {
      const status = error.response.status
      const data = error.response.data
      console.error('[Login] HTTP错误', status, data)
      
      if (status === 400) {
        // 400 参数错误
        errorMessage.value = data.message || '请求参数错误'
      } else if (status === 401) {
        // 401 认证失败（用户名或密码错误）
        errorMessage.value = data.message || '用户名或密码错误'
      } else if (status === 500) {
        // 500 服务器错误
        errorMessage.value = data.message || '服务器错误，请稍后重试'
      } else {
        // 其他错误
        errorMessage.value = data.message || `请求失败（${status}）`
      }
    } else if (error.request) {
      // 请求已发出但没有收到响应
      errorMessage.value = '网络连接失败，请检查后端服务是否启动'
      console.error('[Login] 网络连接失败')
    } else {
      // 其他错误
      errorMessage.value = error.message || '操作失败，请重试'
      console.error('[Login] 其他错误', error.message)
    }
  } finally {
    loading.value = false
    console.log('[Login] 请求处理完成')
  }
}

const handleForgotPassword = () => {
  showMessage('忘记密码功能即将上线','success')
}

const showMessage = (message: string, type: 'success' | 'error' = 'success') => {
  const toast = document.createElement('div')
  toast.textContent = message
  const base = 'position:fixed;left:50%;bottom:80px;transform:translateX(-50%);padding:10px 16px;border-radius:10px;color:#fff;box-shadow:0 6px 20px rgba(0,0,0,0.25);z-index:9999;font-size:14px;opacity:0.95;'
  const bg = type === 'success' ? 'background:#2E8B57;' : 'background:#E74C3C;'
  toast.setAttribute('style', base + bg)
  document.body.appendChild(toast)
  setTimeout(() => {
    toast.style.transition = 'opacity 0.3s ease'
    toast.style.opacity = '0'
    setTimeout(() => { toast.remove() }, 300)
  }, 1800)
}
</script>

<style scoped>
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
}

.login-background {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  z-index: 1;
  filter: blur(15px);
  background: 
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'%3E%3Cpath d='M20,50 C25,30 40,30 50,50 C60,30 75,30 80,50 M50,10 C50,30 30,50 50,70 C70,50 50,30 50,10' fill='none' stroke='rgba(76, 175, 80, 0.1)' stroke-width='2'/%3E%3C/svg%3E") repeat,
    linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
}

.login-background::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: 
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200' viewBox='0 0 200 200'%3E%3Cpath d='M100,20 Q150,20 180,60 Q180,120 120,160 Q60,160 20,120 Q20,60 60,40 Z' fill='rgba(102, 126, 234, 0.05)'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  opacity: 0.7;
}

.floating-leaves {
  position: absolute;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.leaf {
  position: absolute;
  animation: float-down linear infinite;
  pointer-events: none;
}

@keyframes float-down {
  0% {
    transform: translateY(-100px) rotate(0deg);
  }
  100% {
    transform: translateY(100vh) rotate(360deg);
  }
}

.login-card {
  position: relative;
  z-index: 2;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(12px);
  padding: 40px;
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  width: 90%;
  max-width: 450px;
  animation: slide-up 0.6s ease-out;
  border: 1px solid rgba(76, 175, 80, 0.3);
  overflow: hidden;
}

/* 叶脉装饰元素 - 左上角 */
.login-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100px;
  height: 100px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M10,10 Q30,5 50,30 T90,70 M50,10 Q60,20 65,40 Q70,60 55,75' fill='none' stroke='rgba(76, 175, 80, 0.1)' stroke-width='1.5'/%3E%3C/svg%3E");
  background-size: contain;
  opacity: 0.7;
  pointer-events: none;
}

/* 叶脉装饰元素 - 右下角 */
.login-card::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 120px;
  height: 120px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' transform='scaleX(-1) scaleY(-1)'%3E%3Cpath d='M10,10 Q30,5 50,30 T90,70 M50,10 Q60,20 65,40 Q70,60 55,75' fill='none' stroke='rgba(76, 175, 80, 0.1)' stroke-width='1.5'/%3E%3C/svg%3E");
  background-size: contain;
  opacity: 0.7;
  pointer-events: none;
}

.terms-checkbox {
  margin-top: 15px;
}

.terms-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 14px;
  color: #666;
  cursor: pointer;
}

.terms-label input[type="checkbox"] {
  margin-top: 2px;
  width: 16px;
  height: 16px;
  accent-color: #4CAF50;
}

.terms-label a {
  color: #4CAF50;
  text-decoration: underline;
  cursor: pointer;
}

@keyframes slide-up {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.login-header {
  text-align: center;
  margin-bottom: 30px;
}

.logo-section {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 10px;
}

.logo-icon {
  font-size: 3rem;
  animation: rotate-leaf 3s ease-in-out infinite;
}

@keyframes rotate-leaf {
  0%, 100% {
    transform: rotate(0deg);
  }
  50% {
    transform: rotate(10deg);
  }
}

.app-title {
  font-size: 2.5rem;
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0;
  font-weight: bold;
}

.subtitle {
  color: #666;
  font-size: 0.95rem;
  margin: 5px 0 0 0;
}

.login-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 25px;
  background: #f0f0f0;
  padding: 5px;
  border-radius: 10px;
}

.tab-btn {
  flex: 1;
  padding: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: #666;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.3s ease;
}

.tab-btn.active {
  background: linear-gradient(135deg, #4CAF50, #388E3C);
  color: white;
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
}

.tab-btn:not(.active) {
  border-color: rgba(76, 175, 80, 0.3);
  color: #4CAF50;
}

.tab-btn:not(.active):hover {
  background: rgba(76, 175, 80, 0.05);
}

.login-form {
  margin-bottom: 25px;
}

.form-group {
  margin-bottom: 20px;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 12px;
  padding: 0 15px;
  transition: all 0.3s ease;
  border: 1px solid rgba(76, 175, 80, 0.3);
}

.input-wrapper:focus-within {
  background: white;
  box-shadow: 
    0 0 0 2px rgba(76, 175, 80, 0.3),
    0 0 15px rgba(76, 175, 80, 0.4);
  border-color: #4CAF50;
}

.input-icon {
  font-size: 1.1rem;
  margin-right: 10px;
  color: #388E3C;
  /* 替换为线性图标 */
  display: flex;
  align-items: center;
  justify-content: center;
}
.form-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 15px 5px;
  font-size: 1rem;
  outline: none;
  color: #333;
}

.form-input.error {
  color: #f44336;
}

.field-error {
  color: #f44336;
  font-size: 14px;
  margin-top: 4px;
  margin-bottom: 8px;
  padding-left: 15px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23f44336' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'%3E%3C/circle%3E%3Cline x1='12' y1='8' x2='12' y2='12'%3E%3C/line%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'%3E%3C/line%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left center;
  background-size: 14px;
}

.input-wrapper:focus-within {
  box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.2);
  border-color: #4CAF50;
}

.input-wrapper:focus-within .input-icon svg {
  stroke: #4CAF50;
  animation: pulse 1s ease-in-out;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.form-input::placeholder {
  color: #999;
}

.toggle-password {
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 5px;
  font-size: 1.2rem;
  opacity: 0.6;
  transition: opacity 0.3s;
}

.toggle-password:hover {
  opacity: 1;
}

.form-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  font-size: 0.9rem;
}

.remember-me {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  color: #666;
}

.remember-me input[type="checkbox"] {
  cursor: pointer;
}

.forgot-password {
  color: var(--primary-color);
  text-decoration: none;
  transition: color 0.3s;
}

.forgot-password:hover {
  color: var(--primary-dark);
}

.submit-btn {
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #81C784, #388E3C);
  color: white;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
  position: relative;
  overflow: hidden;
}

.submit-btn::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(
    to bottom right,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.2) 50%,
    rgba(255, 255, 255, 0) 100%
  );
  transform: rotate(30deg);
  animation: shine 3s infinite;
}

@keyframes shine {
  0% {
    transform: translateX(-100%) rotate(30deg);
  }
  100% {
    transform: translateX(100%) rotate(30deg);
  }
}

.submit-btn:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
  box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
}

.submit-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.loading-spinner {
  display: inline-block;
}

.error-message {
  margin-top: 15px;
  padding: 12px;
  background: #fee;
  color: #c33;
  border-radius: 8px;
  font-size: 0.9rem;
  text-align: center;
  border: 1px solid #fcc;
  animation: shake 0.3s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}


.login-footer {
  margin-top: 25px;
  text-align: center;
}

.terms {
  font-size: 0.8rem;
  color: #999;
  margin: 0;
}

.terms a {
  color: var(--primary-color);
  text-decoration: none;
}

.terms a:hover {
  text-decoration: underline;
}

@media (max-width: 480px) {
  .login-card {
    padding: 30px 20px;
  }

  .app-title {
    font-size: 2rem;
  }

  .social-buttons {
    flex-direction: column;
  }

  .social-btn {
    flex-direction: row;
    justify-content: center;
  }
}
</style>
